package com.wqz.day.day.up.exception;

import com.wqz.day.day.up.common.BaseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 全局异常处理器
 *
 * @author wuqz
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 业务异常
     */
    @ExceptionHandler(CustomException.class)
    public BaseResult customException(CustomException e) {
        log.error(e.getMessage(), e);
        if (e.getCode() == null) {
            return BaseResult.error(e.getMessage());
        }
        return BaseResult.error(e.getCode(), e.getMessage());
    }
}
